<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>商品详情</title>
        <link rel="stylesheet" type="text/css" href="css/public.css"/>
        <link rel="stylesheet" type="text/css" href="css/book.css"/>
        <link rel="stylesheet" type="text/css" href="css/details.css"/>
    </head>
    <%
        String user_id = (String) session.getAttribute("user_id");
    %>
    <body>
        <div class="head">
            <div class="shouye_head">
                <div class="shou_head">
                    <a href="first.jsp">商城首页</a>
                </div>
                <div class="car">
                    <a href="car.jsp"><img src="images/购物车.png" height="28px">
                        <span>购物车</span>
                    </a>
                </div>
                <div class="login">
                    <div><a href="注册.jsp">登录</a></div>
                    <div><a href="注册.jsp">注册</a></div>
                </div>
            </div>
        </div>
        <div class="search_kuang">
            <div class="search">
                <input type="text" class="text">
                <button><img src="images/搜索图标.png" width="40px"></button>
            </div>
        </div>
        <div class="xi_nav">
            <div class="wrap">
                <ul class="menu-list">
                    <li class="menu"><a href="first.jsp">首页</a></li>
                    <li class="menu"><a href="#">全部分类</a></li>
                    <li class="menu"><a href="#">新品上市</a></li>
                    <li class="menu"><a href="#">热卖推荐</a></li>
                </ul>
            </div>
        </div>
        <div class="product-details">
            <div class="preview" id="preview">
                <img src="${good.pic}" alt="商品图片" class="product-image">
            </div>
            <div class="itemInfo-wrap">
                <div class="x-goodsname">
                    <h3>${good.goods_name}</h3>
                </div>
                <div class="news">
                    <div class="" >
                        ${good.details}
                    </div>
                </div>
                <div class="x-price">
                    <span>￥</span>
                    <div class="x-price_num">${good.unitprice}</div>
                </div>
                <div class="x-action">
                    <div class="liji">
                        <a href="#">立即购买</a>
                    </div>
                    <div class="add_cart">
                        <a href="./addcar.do?id=${good.goods_id}">加入购物车</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="user-comments">
            <h2>用户评论</h2>
            <div class="comments-container">
                <c:forEach items="${comments}" var="comment">
                    <div class="comment">
                        <div class="comment-header">
                            <span class="comment-author"><b>用户:</b> ${comment.user_id}</span>
                            <span class="comment-date"><b>时间:</b> ${comment.comment_time}</span>
                        </div>
                        <div class="comment-body">
                            <p><b>评分:</b> ${comment.rating}</p>
                            <p>${comment.content}</p>
                        </div>
                    </div>
                </c:forEach>
            </div>
        </div>
        <div class="add-comment-section">
            <h2>添加评论</h2>
            <% if (user_id != null) {
                System.out.println(user_id);
            %>
            <form action="./addComment.do" method="get">
                <input type="hidden" name="goods_id" value="${good.goods_id}" />
                <input type="hidden" name="user_id" value="${user_id}" />
                <textarea name="content" rows="4" cols="50" required="required"></textarea>
                <!-- 添加评分部分 -->
                <label for="rating">评分：</label>
                <select name="rating" id="rating">
                    <option value="1">1 星</option>
                    <option value="2">2 星</option>
                    <option value="3">3 星</option>
                    <option value="4">4 星</option>
                    <option value="5" selected>5 星</option>
                </select>
                <button type="submit">提交评论</button>
            </form>
            <% }else { %>
            登录以后才可评论！
            <% } %>
        </div>
    </body>
</html>